#include "Config.h"
#include "Common/Stream.h"
#include "HallClient.h"
#include "Server.h"
#include "Protocols/Protocol.h"

namespace Network {

HallClient::HallClient( int fd, TcpSlaveServer * s, int id )
	: NetworkClient( fd, s, id )
{

}

HallClient::~HallClient()
{

}

void HallClient::onRecv( UInt16 cmd, int len, void * buf )
{
	NetworkClient::onRecv( cmd, len, buf );
	UInt64 pid = m_PlayerId.value();
	MsgHdr hdr( len, cmd, Thread_Logic, id(), pid );
	if (cmd != 0x202)
		printf("Cmd = %u, Pid = %u\n", cmd, pid);
	MSGPOOL().pushMsg( hdr, buf );
}

void HallClient::onDisconnected()
{
	NetworkClient::onDisconnected();
	if ( _clientType == Client_Server )
	{
		UInt64 pid = m_PlayerId.value();
		MsgHdr hdr( 0, 0x201, Thread_Logic, id(), pid );
		MSGPOOL().pushMsg( hdr, nullptr );
	}
	else
	{
		UInt64 pid = m_PlayerId.value();
		MsgHdr hdr( 0, 0x100, Thread_Logic, id(), pid );
		printf("Player Disconnected ---- pid=[%llu]\n", pid);
		MSGPOOL().pushMsg( hdr, nullptr );
	}
}

}